package com.shenzhen.horselive.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;

import androidx.appcompat.app.AppCompatDialog;

import com.shenzhen.horselive.R;


/**
 * SimpleDialog
 *
 * @author LuDaiqian
 */
public class LoadingDialog extends AppCompatDialog {

    protected static final String TAG = "IphoneDialog";

    private View mView;
    private CircularProgressBar loadingIcon;
    private Animation roteAnimation;

    public LoadingDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public LoadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public LoadingDialog(Context context) {
        super(context, R.style.LoadingDialog);
        mView = LayoutInflater.from(context).inflate(R.layout.progress_bar, null);
        loadingIcon = mView.findViewById(R.id.progressbar);
        setContentView(mView);
        setCanceledOnTouchOutside(false);
        roteAnimation = new RotateAnimation(0.0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        roteAnimation.setRepeatCount(-1);
        roteAnimation.setInterpolator(new LinearInterpolator());
        roteAnimation.setDuration(2000);
    }


    @Override
    public void show() {
        super.show();
//        loadingIcon.startAnimation(roteAnimation);
    }

    @Override
    public void onBackPressed() {
        if (onBackListener != null) {
            onBackListener.onLoadingBack();
        }
        super.onBackPressed();
    }

    private OnBackListener onBackListener;

    public void setOnBackListener(OnBackListener onBackListener) {
        this.onBackListener = onBackListener;
    }

    public interface OnBackListener {
        void onLoadingBack();
    }
}
